export default {
    data() {
        return {
            questionList: [], // 问题列表
            page: 1, // 当前页码
            pageSize: 20, // 单页长度
            noMore: false, // 没有更多了
        }
    },
    onLoad() {
        this.getQuestionList(); // 获取常见问题列表
    },
    onReachBottom() {
        if (this.noMore) return false;
        this.page++;
        this.getQuestionList();
    },
    methods: {

        // 获取常见问题列表
        getQuestionList: function() {
            let data = {
                pageNo: this.page,
                pageSize: this.pageSize,
            }
            this.$util.request(this.$api.GetQuestionList, data, "POST").then(res => {
                if (res.returnCode == "SUCCESS") {
                    res.data = res.data || [];
                    if (this.page == 1) this.questionList = [];
                    res.data.forEach((item, index) => {
                        item.on = false; // 默认闭合状态
                        item.title = item.name; // 标题
                        item.answer = item.content; // 描述
                        this.questionList.push(item);
                    })
                    if (res.data.length < this.pageSize) {
                        this.noMore = true;
                    }
                } else {
                    uni.showModal({
                        title: '提示',
                        content: res.returnMessage,
                        showCancel: false,
                    });
                }
            })
        },

        // 问题打开
        openQuestion: function(index) {
            this.questionList[index].on = !this.questionList[index].on;
        }
    },

}